#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   test.py
@Time    :   2020/04/02 10:17:42
@Author  :   Rao Guangxiang 
@Version :   1.0
@Contact :   raogx.vip@hotmail.com
@License :   (C)Copyright 2017-2018, Liugroup-NLPR-CASIA
@Desc    :   None
'''

# here put the import lib


import re

# recv = "6606636324242423660663632424242366"
recv = "6109FFFFFFFE05707070236109FFFFFFFE0570707023"

start_re = re.compile('.*?(61|62|63|64|65|66|67|68|69|6A).*?')
end_re = re.compile('.*?(23).*?')
for i in range(len(start_re.findall(recv))):
    start_res = start_re.match(recv) 
    end_res = end_re.match(recv)
    if start_res:
        start_idx = start_res.start(1)
    else:
        start_idx = -1
    if end_res:
        end_idx = end_res.start(1)
    else:
        end_idx = -1
    if start_idx == 0 and end_idx > 4:
        print(start_idx)
        real_len = int(len(recv) / 2) - 2
        theory_len = int(recv[start_idx+2:start_idx+4], 16)
        print("real_len:%s", real_len)
        print("theory_len:%s", theory_len)
        if real_len >= theory_len :
            cmd = recv[start_idx:end_idx+2]
            print("cmd:%s"%cmd)
            recv = recv[end_idx+2:]
            print("new recv:%s"%recv)
            real_len = int(len(cmd) / 2) - 2
            theory_len = int(cmd[2:4])
            if theory_len == real_len:
                print("长度正确")
            else:
                print("数据多了")
        if real_len < theory_len :
            print("数据少了，继续接收")
    else:
        recv = recv[start_idx:]

# if start_idx == 0 and end_idx > 4:
# else:
#     recv = recv[start_idx:]

print(recv)